window.fbAsyncInit = function() {
    FB.init({
      appId      : '335999063269167',
      xfbml      : true,
      version    : 'v2.2'
    });
};

(function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

window.___gcfg = {lang: 'vi'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

function sendContact(){
    $('.btn-send-contact').click(function(){
        var form = $(this).closest('form');
        $.ajax({
            url: form.attr('action'),
            type: form.attr('method'),
            data: form.serialize(),
            cache: false,
            success: function(data){
                $('#flg_message').removeClass('hidden').hide();
                $('#flg_message h4.message-title').html(data.title);
                if(data.code===1){
                    $('#flg_message div.message-text').html('');
                    $('#flg_message').removeClass('alert-danger').addClass('alert-success');
                } else {
                    $('#flg_message div.message-text').html(data.text);
                    $('#flg_message').addClass('alert-danger').removeClass('alert-success');
                }
                $('#flg_message').slideDown();
                htmlScrollToMessage();
            }
        });
    });
}

function enable_contact_submit_button(){
    $($('#recaptcha').attr('data-btnsubmit')).attr('disabled', false);
}

function makeToast(message, code){
    var icon     = 'fa fa-times';
    var m_class  = 'error';
    var bg_class = {'success': '#dff0d8', 'error': '#f2dede'};
    if(code==1){
        icon='fa fa-check-circle';
        m_class = 'success';
    }
    // $('#toast .toast-wrapper').css('background', bg_class[m_class]);
    $('#toast .toast-state i').removeClass().addClass(icon);
    $('#toast .toast-message').html(message);

    $('#toast').show().removeClass()
    .addClass('fadeInUp animated')
    .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
        $(this).removeClass();
        setTimeout(function(){$('#toast .toast-close').click();}, 1000);
    });

    $('#toast .toast-close').click(function(){
        $('#toast').removeClass()
        .addClass('fadeOutUp animated')
        .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
            $(this).removeClass();
            $(this).hide();
        });
    });
}